// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
/**
 * 分红
 */


let base = require("panelBase")
let viewConfig = {
    btn_back:{
        node:null,
        name:"btn_back",
        eventType:"click",
        cb:"onBtnBackClick"
    },
    cake:{
        node:null,
        name:"fh_invite/cake",
    },
    btn_invite:{
        node:null,
        name:"fh_invite/btn_invite",
        eventType:"click",
        cb:"onBtnInviteClick"
    },
    //邀请好友进度条
    fh_pb:{
        node:null,
        name:"fh_invite/fh_pb"
    },
    //进度条文字
    fh_pb_des:{
        node:null,
        name:"fh_invite/pb_des"
    },

    invite_des:{
        node:null,
        name:"fh_invite/invite_des"
    },

    //广告分红相关

    //分红详情
    btn_banner_detail:{
        node:null,
        name:"fh_banner/btn_detail",
        eventType:"click",
        cb:"onBtnBannerDetailClick"
    },
    // 昨日收益
   zrsy_num:{
       node:null,
       name:"fh_banner/fh_zrsy/coin_num"
   },
   // 历史收益
   lssy:{
       node:null,
       name:"fh_banner/fh_lssy/coin_num"
   },

   ///每一个分红蛋糕收益

   cake_gain_detail:{

       node:null,
       name:"fh_cake_gain/btn_detail",
       eventType:"click",
       cb:"onBtnCakeGainClick"
   },
   //昨日收益
   fh_zrsy:{
       node:null,
       name:"fh_cake_gain/detail/zrsy"
   },
   //全网产出
   fh_total:{
       node:null,
       name:"fh_cake_gain/detail/qwzs"
   },
   //今日产出
   fh_today_gain:{
       node:null,
       name:"fh_cake_gain/detail/jrcc"
   },
   // 特产出
   fh_tcc:{
    node:null,
    name:"fh_cake_gain/detail/tcc"
   },


   ///规则相关


   fh_cake_detail:{
       node:null,
       name:"fh_cake_rule/btn_detail",
       eventType:"click",
       cb:"onBtnRuleDetailClick"
   },


   //邀请口令相关

   invite_btn_close:{
       node:null,
       name:"invite/btn_close",
       eventType:"click",
       cb:"onBtnInviteCloseClick",
   },
   // 口令内容
   invite_des:{
        node:null,
        name:"invite/des",
   },
   //分享
   invite_btn_share:{
        node:null,
        name:"invite/btn_share",
        eventType:"click",
        cb:"onBtnShareClick",
   },
   myCake:{
       node:null,
       name:"myCake"
   },
   btn_fh:{
       node:null,
       name:"btn_fh",
       eventType:"click",
       cb:"onBtnFhClick",
       scale:2,
   }

};
cc.Class({
    extends: base,

    properties: {
        
    },

    init(){
        this._super(viewConfig);
        this.showInvitePanel(false,null)
        this.isInited = true;
        cc.tg.eventCenter.addEvent("onShowInvite",()=>{
            this.showInvitePanel(true,123456);
        })
        this.onHide();
    },

    onShow(){
        this._super();

        setTimeout(()=>{
            let testData = {
                inviteNum:15,
                b_zrsy:1024.00,
                b_lssy:10240.00,
                zrsy:180.30,
                total:20,
                jrcc:0,
                tcc:3000,
            }
           let percent = testData.inviteNum / 50;
           let pb = viewConfig["fh_pb"].node;
           pb.getComponent(cc.ProgressBar).progress = percent;
           let des = "已完成"+ percent* 100 +"%, 达100%必得"
           this.updateInfo(viewConfig["fh_pb_des"].node,des,cc.Label);
           this.updateInfo(viewConfig["zrsy_num"].node,testData.b_zrsy,cc.Label);
           this.updateInfo(viewConfig["lssy"].node,testData.b_lssy,cc.Label);
           this.updateInfo(viewConfig["fh_zrsy"].node,testData.zrsy,cc.Label);
           this.updateInfo(viewConfig["fh_total"].node,testData.total,cc.Label);
           this.updateInfo(viewConfig["fh_today_gain"].node,testData.jrcc,cc.Label);
           this.updateInfo(viewConfig["fh_tcc"].node,testData.tcc,cc.Label);
        },1000)
    },

    onBtnBackClick(){
        this.onHide();
    },

    onBtnInviteClick(){
       this.showInvitePanel(true,123456)
    },

    onBtnBannerDetailClick(){
        cc.log("on click bd");
    },
    onBtnCakeGainClick(){
        cc.log("on click cgd");
    },
    onBtnRuleDetailClick(){
        cc.log("on click rule detail ");
    },

    onBtnInviteCloseClick(){
        this.showInvitePanel(false,null);
    },

    onBtnShareClick(){
        let str = viewConfig["invite_des"].node.getComponent(cc.Label).string;
        cc.tg.adDataCenter.copy(str);
        cc.log("on click share");
    },

    showInvitePanel(isShow,info){
            let invite = viewConfig["invite_btn_close"].node.parent;
            if(!isShow || !info)
            {
                invite.active = false;
            }
            else
            {
                invite.active = true;
            }
    },

    onBtnFhClick(){
        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"makeFh",active:true})
        this.onHide();
    },

    onDestroy(){
        for(let key in viewConfig)
        {
            viewConfig[key].node = null;
        }
    },
});
